App({
  onLaunch(options) {
    // 初始化全局配置
    this.initGlobalConfig();
  },
  onShow(options) {
    // Do something when show.
  },
  onHide() {
    // Do something when hide.
  },
  onError(msg) {
    console.log('小程序错误:', msg)
  },

  /**
   * 初始化全局配置
   */
  initGlobalConfig: function() {
    try {
      const systemInfo = tt.getSystemInfoSync();
      const isSimulator = systemInfo.platform === 'devtools';

      // 设置API基础URL - 使用8080端口
      let apiBaseUrl;
      if (isSimulator) {
        apiBaseUrl = 'http://127.0.0.1:8080';
      } else {
        // 真机环境 - 使用实际检测到的IP地址
        apiBaseUrl = 'http://10.12.173.82:8080';
      }

      this.globalData.apiBaseUrl = apiBaseUrl;
      this.globalData.isSimulator = isSimulator;

      console.log('全局配置初始化完成:', {
        apiBaseUrl: apiBaseUrl,
        isSimulator: isSimulator,
        platform: systemInfo.platform
      });

    } catch (error) {
      console.error('初始化全局配置失败:', error);
      // 设置默认值
      this.globalData.apiBaseUrl = 'http://127.0.0.1:8080';
      this.globalData.isSimulator = true;
    }
  },

  globalData: {
    apiBaseUrl: '',
    isSimulator: true
  }
})
